#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QMessageBox *mess = new QMessageBox(this);
    mess->setWindowTitle("这是一个消息框");
    mess->setText("这是对话框文本");
    mess->setIcon(QMessageBox::Warning);
    // 标准按钮中，是没办法进行信号槽的连接，是QMessageBox自己生成的
    // mess->setStandardButtons(QMessageBox::Save | QMessageBox::Ok | QMessageBox::Cancel);

    QPushButton *but = new QPushButton("按钮",mess);
    mess->addButton(but,QMessageBox::AcceptRole);

    // mess->show();
    mess->exec();
    // delete mess;
    mess->setAttribute(Qt::WA_DeleteOnClose);
}

